package secretary;

import java.sql.SQLException;
import com.sun.rowset.CachedRowSetImpl;
import flexibility.userData;
import basic.ClientConsole;

public class checkOpenSemester {
	private boolean isOpen = false;
	
	public boolean isOpenSemester(ClientConsole secretaryConnection,CachedRowSetImpl crs, userData secretaryData, int semester  ) {
		/*
		 * this will check if there is an open semester under planning
		 */
		switch(semester){
		case 1://case of next semester
			secretaryData.deleteAll();
			secretaryData.addData(8);
			secretaryData.addData(1);
			secretaryConnection.acceptMsg(secretaryData);
			crs = secretaryConnection.getResults();
			try {
				if (crs.next() == false) {// no new open semester
					isOpen = false;
				} else {
					isOpen = true;// there is an open semester already which has not
									// been activated
				}

			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			break;
			
		case 0://case of current semester
			secretaryData.deleteAll();
			secretaryData.addData(19);
			secretaryData.addData(1);
			
			secretaryConnection.acceptMsg(secretaryData);
			crs = secretaryConnection.getResults();
			try {
				if (crs.next() == false) {// no new open semester
					isOpen = false;
					System.out.println("fuck off");	
				} else {
					isOpen = true;// there is an open semester already which has not
						// been activated
				}

			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			break;
		}
		
		return isOpen;
	}
}
